package com.project.service.impl;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @Title: BaseService
 * @Package: com.project.service.impl
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/7/13 - 17:32
 */
@SuppressWarnings("all")
public class BaseService {
    private static SqlSessionFactory factory;
    static {
        try {
            Reader r= Resources.getResourceAsReader("mybatis.cfg.xml");
            factory=new SqlSessionFactoryBuilder().build(r);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public SqlSession getSession(){
        return factory.openSession();
    }
}
